import CommonLedgerStore from "./CommonLedgerStore";
import * as Apis from "../../apis/Api";
import * as Bctt from "../../constants/BaseListConstant";
import { observable, action } from 'mobx';
import { Button } from "antd";
import { WeaTableNew, WeaForm } from 'comsMobx';
const { TableStore } = WeaTableNew;

class MyContractStore extends CommonLedgerStore {
	@observable mainTabKey = "mine";//主tab的key
	@observable isShowResource=false;
	@observable attentions={};
	@observable conditionTop = {};
	@observable hrmType = 0;
	
	// constructor(props) {
	// 	super(props);
	// 	this.searchInputName = "cons_name";
	// }

	

	@action
    componentDidMount = () => {
		this.shareStore = new weaCube.common.ShareStore();
        this.Card = new weaCube.common.CardStore();
		this.getConditionTop();
		this.loading = true;
		Apis.getModeInfo({}).then(data => {
			this.cubeParams = data[this.routerParams.page];
			this.searchInputName = data[this.routerParams.page].cons_name;
			let requestParams = {...this.cubeParams,...this.routerParams,...{labelid:this.mainTabKey}};
			this.getInitInfoFromCube(requestParams, this.initInfoComponentInitCallBack);
			this.getTableData(requestParams, this.tableComponentInitCallBack);
			this.getRpData(requestParams, this.rpComponentInitCallBack);
			this.getRightMenuFromCustom(requestParams, this.rightMenuFromCustomComponentInitCallBack);
			this.getConditionFromCube(requestParams, this.conditionComponentInitCallBack);
		});
        
	}
	
	@action
    componentWillUnmount = () => {
        this.loading = false;
        this.viewTop = true;
        this.iconBgcolor = "";
        this.topInfo = { "titleName": "", "titleIcon": "", "iconBgcolor": "" };//头部信息
        this.rightMenu = [];
        this.rightMenuFromCube = [];//建模的右键
        this.rightMenuFromCustom = [];//自定义的右键
        this.showSearchAd = false;
        this.searchKey = "";
        this.searchConditionForm = new WeaForm();
        this.searchConditionComponents = {};
        this.tableStore = new TableStore();
        this.routerParams = {};
        this.cubeParams = {};
        this.searchInputName = Bctt.TAB_SEARCH_INPUT_NAME;
        this.contractType = [];
        this.rpData = [];//普通台账报表头
        this.riskRpData = [];//风险台账报表头
        this.commonParams = {};//用来存储dataKey,formId,customid,guid等
        this.synergyParams = { isUse: false, isShow: false, refId: -1, tabKey: "0" };
        this.shareStore = {};
        this.searchBaseParams = {};
        this.dialog = {visible:false};
		this.Card = {};
		
		this.mainTabKey = "mine";//主tab的key
		this.isShowResource=false;
		this.attentions={};
		this.conditionTop = {};
		this.hrmType = 0;

        window._cubeCard={};
    }

	getInitInfoFromCube(requestParams,callBackFn){
		Apis.getInitInfoFromCube(requestParams).then(data => {
			callBackFn(data);
		});
	}

	@action
	getTableData(requestParams, callBackFn) {
		this.getAttentions();
		Apis.getListFromCube(requestParams).then(data => {
			callBackFn(data);	
		});
	}

	getRpData(requestParams, callBackFn) {
		Apis.getLedgerRpData(requestParams).then(data => {
			callBackFn(data);
		});
	}

	getRightMenuFromCustom(requestParams,callBackFn){
		Apis.getRightMenuFromCustom(requestParams).then(data => {
			callBackFn(data);
		});
	}
	
	getConditionFromCube(requestParams,callBackFn){
		Apis.getConditionFromCube(requestParams).then(data => {
			callBackFn(data);
		});
	}
	
	@action
	getAttentions(){
		Apis.getAttentions().then(data => {
			this.attentions = data.datas;
		});
		
	}

	@action
    doAttention =(store,conId)=>{
		store =(store===0)?1:0;
        let params = {'store':store,'contractId':conId};
        Apis.doAttention(params).then(data => {
			this.getAttentions();
        });
    }

	@action 
    changeMainTab=(key="mine")=>{
		this.mainTabKey = key;
		if(key!=="mine"){
			delete this.searchBaseParams.resourceid;
		}
		const params = {...this.searchBaseParams,...{labelid:key,page:'home'}};
		this.doSearch(params);
		this.isShowResource = (this.mainTabKey=="mine"&&(this.conditionTop.hrmList||[]).length>0);
		this.hrmType = parseInt(params.hrmtype||0);

	}
	
	/**顶部快捷搜索项 */
	@action 
	getConditionTop = (params={})=>{
		this.isShowResource = false;
		const mainTabKeyParams = {labelid:this.mainTabKey};
		const newParams = {...params,...mainTabKeyParams};
		Apis.getConditionTop(newParams).then(data => {
			this.conditionTop = data;
			this.isShowResource = this.mainTabKey=="mine"&&(data.hrmList||[]).length>0;
		});
	}
	@action
	saveHrmList =(data)=>{
        this.conditionTop.hrmList = data;
    }
	
}

export default MyContractStore;